﻿using System;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;

namespace PengSW.Monitor
{
    public class MonitorCollection : ObservableCollection<Monitor>
    {
        protected override void ClearItems()
        {
            foreach (Monitor aMonitor in this) aMonitor.Stop();
            base.ClearItems();
        }

        protected override void InsertItem(int index, Monitor item)
        {
            if (item == null) return;
            base.InsertItem(index, item);
            item.Start();
        }

        protected override void RemoveItem(int index)
        {
            if (index < 0 || index > this.Count) return;
            Items[index].Stop();
            base.RemoveItem(index);
        }

        protected override void SetItem(int index, Monitor item)
        {
            if (index < 0 || index > this.Count) return;
            Items[index].Stop();
            base.SetItem(index, item);
            Items[index].Start();
        }
    }
}
